<!DOCTYPE html>
<html>
<!-- Created by GNU Texinfo 7.1.1, https://www.gnu.org/software/texinfo/ -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<!-- This file documents the use of the GNU compilers.

Copyright © 1988-2023 Free Software Foundation, Inc.

Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3 or
any later version published by the Free Software Foundation; with the
Invariant Sections being "Funding Free Software", the Front-Cover
Texts being (a) (see below), and with the Back-Cover Texts being (b)
(see below).  A copy of the license is included in the section entitled
"GNU Free Documentation License".

(a) The FSF's Front-Cover Text is:

A GNU Manual

(b) The FSF's Back-Cover Text is:

You have freedom to copy and modify this GNU Manual, like GNU
     software.  Copies published by the Free Software Foundation raise
     funds for GNU development. -->
<title>Loop-Specific Pragmas (Using the GNU Compiler Collection (GCC))</title>

<meta name="description" content="Loop-Specific Pragmas (Using the GNU Compiler Collection (GCC))">
<meta name="keywords" content="Loop-Specific Pragmas (Using the GNU Compiler Collection (GCC))">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<meta name="Generator" content="makeinfo">
<meta name="viewport" content="width=device-width,initial-scale=1">

<link href="index.html" rel="start" title="Top">
<link href="Indices.html" rel="index" title="Indices">
<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
<link href="Pragmas.html" rel="up" title="Pragmas">
<link href="Function-Specific-Option-Pragmas.html" rel="prev" title="Function Specific Option Pragmas">
<style type="text/css">
<!--
a.copiable-link {visibility: hidden; text-decoration: none; line-height: 0em}
div.example {margin-left: 3.2em}
kbd.key {font-style: normal}
span:hover a.copiable-link {visibility: visible}
-->
</style>


</head>

<body lang="en_US">
<div class="subsection-level-extent" id="Loop_002dSpecific-Pragmas">
<div class="nav-panel">
<p>
Previous: <a href="Function-Specific-Option-Pragmas.html" accesskey="p" rel="prev">Function Specific Option Pragmas</a>, Up: <a href="Pragmas.html" accesskey="u" rel="up">Pragmas Accepted by GCC</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Indices.html" title="Index" rel="index">Index</a>]</p>
</div>
<hr>
<h4 class="subsection" id="Loop_002dSpecific-Pragmas-1"><span>6.62.16 Loop-Specific Pragmas<a class="copiable-link" href="#Loop_002dSpecific-Pragmas-1"> &para;</a></span></h4>

<dl class="table">
<dt><a id="index-pragma-GCC-ivdep"></a><span><code class="code">#pragma GCC ivdep</code><a class="copiable-link" href="#index-pragma-GCC-ivdep"> &para;</a></span></dt>
<dd>
<p>With this pragma, the programmer asserts that there are no loop-carried
dependencies which would prevent consecutive iterations of
the following loop from executing concurrently with SIMD
(single instruction multiple data) instructions.
</p>
<p>For example, the compiler can only unconditionally vectorize the following
loop with the pragma:
</p>
<div class="example smallexample">
<pre class="example-preformatted">void foo (int n, int *a, int *b, int *c)
{
  int i, j;
#pragma GCC ivdep
  for (i = 0; i &lt; n; ++i)
    a[i] = b[i] + c[i];
}
</pre></div>

<p>In this example, using the <code class="code">restrict</code> qualifier had the same
effect. In the following example, that would not be possible. Assume
<em class="math">k &lt; -m</em> or <em class="math">k &gt;= m</em>. Only with the pragma, the compiler knows
that it can unconditionally vectorize the following loop:
</p>
<div class="example smallexample">
<pre class="example-preformatted">void ignore_vec_dep (int *a, int k, int c, int m)
{
#pragma GCC ivdep
  for (int i = 0; i &lt; m; i++)
    a[i] = a[i + k] * c;
}
</pre></div>

</dd>
<dt><a id="index-pragma-GCC-unroll-n"></a><span><code class="code">#pragma GCC unroll <var class="var">n</var></code><a class="copiable-link" href="#index-pragma-GCC-unroll-n"> &para;</a></span></dt>
<dd>
<p>You can use this pragma to control how many times a loop should be unrolled.
It must be placed immediately before a <code class="code">for</code>, <code class="code">while</code> or <code class="code">do</code>
loop or a <code class="code">#pragma GCC ivdep</code>, and applies only to the loop that follows.
<var class="var">n</var> is an integer constant expression specifying the unrolling factor.
The values of <em class="math">0</em> and <em class="math">1</em> block any unrolling of the loop.
</p>
</dd>
</dl>

</div>



</body>
</html>
